﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using UnliQ.ServiceLayer;
using UnliQ.Service.Contracts;
using UnliQ.Web.Models;

namespace UnliQ.Web.Controllers
{
    public class QueueController : UnliQController<IQueueService>
    {
        #region [Private Member(s)]
       

        #endregion

        #region [Constructor(s)]
        public QueueController(IQueueService service)
        {
            this.service = service;
        }

        public QueueController()
        {
            this.service = new QueueService();
        }

        #endregion

        public ActionResult Check()
        {
            return View();
        }

        public ActionResult Index()
        {
            return View();            
        }

        [Authorize]
        public ActionResult SubscriberDash()
        {
            return View();
        }

		[Authorize] 		
        public ActionResult ClientTriggerDash()
        { 
            return View();
        }

        [Authorize(Roles="Admin")]
        public ActionResult AdminDash()
        {
            return View();
        }

        public Response<int> InsertEvent(EventDTO events)
        {
            QueueService service = new ServiceLayer.QueueService();
            return service.Insert(events);
        }

        public Response UpdateEvent(EventDTO events)
        {
            QueueService service = new ServiceLayer.QueueService();
            return service.Update(events);
        }

        public Response DeleteEvent(int Id)
        {
            QueueService service = new ServiceLayer.QueueService();
            return service.Delete(Id);
        }

        public JsonResult GetEvents()
        {
            var result = this.service.GetAllEvents();

            if (result.IsSuccessful)
            {
                GridViewData<EventDTO> gridViewData = new GridViewData<EventDTO>();
                GridViewDataGenerator<EventDTO>.GenerateGridViewData(ref gridViewData, result.ReturnModel);
                return Json(gridViewData, JsonRequestBehavior.AllowGet);
            }

            return Json(result);

        }

        public JsonResult GetUserTriggeredEvents(int userId)
        {
            var result = this.service.GetUserTriggeredEvents(userId);

            if (result.IsSuccessful)
            {
                GridViewData<EventDTO> gridViewData = new GridViewData<EventDTO>();
                GridViewDataGenerator<EventDTO>.GenerateGridViewData(ref gridViewData, result.ReturnModel);
                return Json(gridViewData, JsonRequestBehavior.AllowGet);
            }

            return Json(result);

        }

    }

    public class Event
    {
        public string Name { get; set; }
        public string Description { get; set; }
        public string TriggeredBy { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
    }
}
